package com.learn.rabbitmq.controller;

import com.learn.rabbitmq.config.ConfirmConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 发送延迟消息
 */
@Slf4j
@RestController
@RequestMapping("/confirm")
public class SendMesController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    //开始发消息 基于插件 加过期时间
    @GetMapping("/sendMsg/{message}")
    public void sendMessage(@PathVariable String message) {

        //设置回调内容
        CorrelationData correlationData = new CorrelationData("1");
        //发送消息
        rabbitTemplate.convertAndSend(
                ConfirmConfig.CONFIRM_EXCHANGES_NAME,
                ConfirmConfig.CONFIRM_ROUTING_KEY_NAME,
                message,correlationData);
        log.info("发送的消息:{}", message+"key1");
        //设置回调内容
        CorrelationData correlationData2 = new CorrelationData("2");
        //发送消息
        rabbitTemplate.convertAndSend(
                ConfirmConfig.CONFIRM_EXCHANGES_NAME,
                ConfirmConfig.CONFIRM_ROUTING_KEY_NAME+"2",
                message,correlationData2);
        log.info("发送的消息:{}", message+"key2");
    }


}
